//
//  MLLose.m
//  WaterProof
//
//  Created by victor0321 on 12/1/9.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "MLLose.h"

@interface MLLose (PrivateMethods)
-(void) restartItemTouched:(id)sender;
-(void) mainMenuItemTouched:(id)sender;
@end

@implementation MLLose

+(id) sceneWithColor:(ccColor4B)color {
    CCLOG(@"===========================================");
    CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);
    return [[[self alloc] initColor:color] autorelease];
}

-(id) initColor:(ccColor4B)color
{
    if ((self = [super initWithColor:color]))
    {
        screenSize = [[CCDirector sharedDirector]winSize];
        self.isTouchEnabled=YES;
        
        CCSprite* winBackground = [CCSprite spriteWithFile:@"lose.png"];
        winBackground.position = CGPointMake(screenSize.width/2, screenSize.height+winBackground.contentSize.height/2);
        CGFloat moveDis = (screenSize.height+winBackground.contentSize.height)/2;
        CCMoveBy* move = [CCMoveBy actionWithDuration:1 position:CGPointMake(0, -(moveDis))];
        CCEaseBackOut* ease = [CCEaseBackOut actionWithAction:move];
        [winBackground runAction:ease];
        
        CCSprite* restart = [CCSprite spriteWithFile:@"win_lose_restart.png"];
        CCSprite* restartSelected = [CCSprite spriteWithFile:@"win_lose_restart.png"];
        restartSelected.color = ccGRAY;
        CCMenuItemSprite* restartItem = [CCMenuItemSprite itemFromNormalSprite:restart selectedSprite:restartSelected target:self selector:@selector(restartItemTouched:)];
        
        CCSprite* mainMenu = [CCSprite spriteWithFile:@"win_lose_mainmenu.png"];
        CCSprite* mainMenuSelected = [CCSprite spriteWithFile:@"win_lose_mainmenu.png"];
        mainMenuSelected.color = ccGRAY;
        CCMenuItemSprite* mainMenuItem = [CCMenuItemSprite itemFromNormalSprite:mainMenu selectedSprite:mainMenuSelected target:self selector:@selector(mainMenuItemTouched:)];
        
        CCMenu* menu = [CCMenu menuWithItems:restartItem, mainMenuItem, nil];
        [menu setPosition:CGPointMake(winBackground.contentSize.width/2+10, winBackground.contentSize.height/2 - 80)];
        [menu alignItemsHorizontallyWithPadding:10];
        
        [winBackground addChild:menu];
        [self addChild:winBackground];
    }
    return self;
}

-(void) restartItemTouched:(id)sender{
    [[MLGameLayer sharedLayer] restartStage];
}

-(void) mainMenuItemTouched:(id)sender{
    [[MLGameLayer sharedLayer] transitionToMenu];
}

- (void) dealloc
{
    CCLOG(@"===========================================");
    CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);
    
    [super dealloc];
}

@end
